package thread.java20221201;

/**
 * 线程等待:join()
 *
 */
public class Demo15 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("包包安检通过");
        });
        t1.start();

        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("人安检通过");
        });
        t2.start();
        //main线程要等待t1和t2 执行完
        t1.join(5000);//等待t1 执行完成
        t2.join();//等待t2 执行完成
        System.out.println("全部安检通过");

    }
}
